import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 1913. 两个数对之间的最大乘积差
 * https://leetcode-cn.com/problems/maximum-product-difference-between-two-pairs/
 */
public class Solutions_1913 {
    public static void main(String[] args) {
        int[] nums1 = {5, 6, 2, 7, 4};  // output: 34
        int[] nums2 = {4, 2, 5, 9, 7, 4, 8};  // output: 64

        List<int[]> inputs = new ArrayList<>();
        inputs.add(nums1);
        inputs.add(nums2);

        for (int[] input : inputs) {
            int result = maxProductDifference(input);
            System.out.println(result);
        }
    }

    public static int maxProductDifference(int[] nums) {
        Arrays.sort(nums);
        int len = nums.length;
        return (nums[len - 1] * nums[len - 2]) - (nums[0] * nums[1]);
    }
}
